<html>
<head>
<script>
function log(message) {
	var node = document.createElement('p');
	node.textContent = message;
	document.body.appendChild(node);
}

function createWorker() {
	var worker = new SharedWorker('shared-worker.js', 'SharedWorker');
	worker.port.onmessage = function(event) {
		log(event.data);
		window.parent.postMessage(event.data, '*');
	}
	worker.port.start();
	worker.port.postMessage('Connection test');
}

window.onload = function() {
	try {
		createWorker(false);
	} catch (exception) {
		log(exception.name);
		window.parent.postMessage(exception.name, '*');
	}
}

window.onmessage = function(e) {
	try {
		createWorker(true);
	} catch (exception) {
		log(exception.name);
		window.parent.postMessage(exception.name, '*');
	}
}
</script>
</head>
<body>
</body>
</html>
